1. Field of the Invention
The disclosure relates generally to embedded systems and methods for thread and buffer management thereof, and, more particularly to embedded systems and methods for threads and buffer management thereof capable of simultaneously processing multiple threads.
2. Description of the Related Art
Embedded systems have been widely implemented in various fields, such as machine controllers, set-top boxes of tool machines, information home appliances, mobile phones, trip computers and so on. The embedded system is mainly used for remote controlling and data acquisition to perform remote monitoring of the tool machine and frequency diagnosis operation of the tool machine in the case of a set-top box for the tool machine. Generally, when the tool machine performs the frequency diagnosis operation, the set-top box of the tool machine should keep in high speed and stable acquiring frequency for acquiring data from the tool machine. The acquired data is processed first and the processed data is transmitted to the remote side. If the acquiring frequency of data is not stable during the data acquisition operation (i.e. the data can not be acquired at a stable frequency), misjudgment may be caused due to the insufficiency of the acquired data. However, due to the cost consideration, the embedded system is typically composed of a cheap central processing unit (CPU), thus its operation capability may be limited. When the processing unit of the embedded system requires to acquire data, process the acquired data and output the processed data simultaneously, the processing unit may not be capable of executing the thread, which requires to acquire data on time, in time to acquire data on schedule due to the limited operation capability of the processing unit and/or previously acquired data may not be processed on time leading to out of the memory. Then, the acquiring will be delayed and stability of signal acquiring will be affected.
Recently, with the growths in computer techniques and processor architectures advance, processors with multi-cores have become more and more popular. The multi-core indicates a technology that implements concurrent processing of multiple threads at the same time on hardware. Due to the better performance and the well hardware support of the multi-core processor, the processing/computer systems with the multi-core processor can execute more than one thread at the same time so as to improve overall processing performance. Due to the cost consideration, the embedded system adapting a single-core processor is generally used and the single-core is utilized to simultaneously perform the data acquisition and data process operations. To prevent the acquiring frequency from being affected by real time diagnosis processing, producer and consumer modes are utilized to separately perform the data acquisition operation by one thread (i.e. the producer) and perform the data process operation by another thread (i.e. the consumer) so as to avoid interference and waiting between each other. However, although the data acquisition and data process operations can be separated by using different threads, the execution order between the two types of threads can not be controlled by the processor since the execution order still follows the sequence scheduled by the operation system (OS). Thus, stability of data acquisition (i.e. stably acquiring data on schedule) may not be guaranteed when the processor and memory loading in the embedded system is almost full. In addition, a shared memory (also referred to as shared buffer) is utilized to be accessed by different threads. Since the storage space of the shared memory (buffer) is limited, it may easily become out of memory after a long time operation, thereby resulting in data loss.
It is therefore a desire to provide a method for threads control and buffer management for use in the embedded system that may, under a condition that the hardware cost for the embedded system is not significantly increased and the specifications of the processor and the memory within the embedded system are not enhanced, keep acquiring data with high frequency and performing data process and output operation at the same time without the drawbacks of acquiring data with unstable acquiring frequency and resulting in data loss due to the problems of insufficient spaces of the memory buffer.